package control.cafe;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.board.BoardService;
import model.boardlist.BoardListService;
import model.boardlist.BoardListVO;
import model.member.MemberService;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class CafeController extends MultiActionController {
	//boardListService,BoardService - DI 접근
	private BoardListService boardListService;
	private BoardService boardService;
	private MemberService memberService;
	public void setBoardListService(BoardListService boardListService) {
		this.boardListService = boardListService;
	}
	public void setBoardService(BoardService boardService) {
		this.boardService=boardService;		
	}
	public void setMemberService(MemberService memberService){
		this.memberService=memberService;
	}

	/**
	 * cafe(다방) 으로 입장
	 * 		&
	 * 세션으로 카페 내 게시판들 목록 뽑기
	 * 		&
	 * 모든 게시판의 통합 목록 보기
	 */
	public ModelAndView cafe(HttpServletRequest request,
			HttpServletResponse response, HttpSession session) throws Exception {
		if(session.getAttribute("count")==null||
				session.getAttribute("list")==null){
			//회원수 조회 - info.jsp에 쓰일 부분
			String count=memberService.countId();
					//System.out.println("컨트롤러 - countId - "+count);
			session.setAttribute("count", count);
			//보드 리스트를 받아오기 - left.jsp에 쓰일 부분
			List<BoardListVO> vo = boardListService.boardList();
			session.setAttribute("list", vo);
		}
		//게시물의 내용 전부다 받아오기 - main.jsp에 쓰일 부분
		String view=request.getParameter("view");
		String page_no=request.getParameter("pageNo");
		HashMap map=new HashMap();
		map.put("view", view);
		map.put("page_no", page_no);
				System.out.println(boardService.getContentListAll(map)+"controller");
		return new ModelAndView("home","alvo",boardService.getContentListAll(map));
	}
	/**
	 * 모든 게시판을 대상으로 검색하기!!
	 * searchAllBoard method
	 */
	public ModelAndView searchAllBoard(HttpServletRequest request,
			HttpServletResponse response, HttpSession session) throws Exception {
		if(session.getAttribute("count")==null||
				session.getAttribute("list")==null){
			//회원수 조회 - info.jsp에 쓰일 부분
					//System.out.println("지금 시작전...컨트롤<");
			String count=memberService.countId();
					//System.out.println("컨트롤러 - countId - "+count);
			session.setAttribute("count", count);
			//보드 리스트를 받아오기 - left.jsp에 쓰일 부분
			List<BoardListVO> vo = boardListService.boardList();
			session.setAttribute("list", vo);
		}
		//게시물의 내용 전부다 받아오기 - main.jsp에 쓰일 부분
		String str=request.getParameter("str");
		String kind=request.getParameter("searchKind");
		String view=request.getParameter("view");
		String page_no=request.getParameter("pageNo");
				//System.out.println("controller : "+request.getParameter("pageNo"));
		HashMap map=new HashMap();
		map.put("kind", kind);
		map.put("str", str);
		map.put("view", view);
		map.put("page_no", page_no);
				//System.out.println("controller : "+map);
		return new ModelAndView("home","alvo",boardService.allSearchBoard(map));
	}
}
